import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store';
// 登录
const Login = () =>
    import ('../views/mine/Login.vue');
// 修改密码
const ChangePassword = () =>
    import ('../views/mine/ChangePassword.vue');
// 我的
const Mine = () =>
    import ('../views/mine/Mine.vue');
// 工作台
const DeskTop = () =>
    import ('../views/desktop/DeskTop.vue');
// 消息中心
const Notice = () =>
    import ('../views/notice/Notice.vue');
// 消息列表
const NoticeList = () =>
    import ('../views/notice/NoticeList.vue');
// 绩效考核
const PerformanceTabs = () =>
    import ('../views/performance/PerformanceTabs.vue');
// 绩效结果
const MyPerformance = () =>
    import ('../views/performance/MyPerformance.vue');
// 考核模板
const AppraisalIndexDescription = () =>
    import ('../views/performance/AppraisalIndexDescription.vue');

// 招商考核
const Business = () =>
    import ('../views/business/Business.vue');
// 我要申请
const Application = () =>
    import ('../views/business/Application.vue');
// 我审批的
const Accraditation = () =>
    import ('../views/business/Accraditation.vue');
// 我发起的
const Sponsored = () =>
    import ('../views/business/Sponsored.vue');
// 下属员工
const Subordinates = () =>
    import ('../views/business/Subordinates.vue');
// 下属员工详情
const SubordinatesInfo = () =>
    import ('../views/business/SubordinatesInfo.vue');
// 审批详情
const ApproveDetail = () =>
    import ('../views/business/ApproveDetail.vue');

// 七天延期
const SevenDelay = () =>
    import ('../views/sevenDelay/SevenDelay.vue');
// 我要申请
const ApplicationDelay = () =>
    import ('../views/sevenDelay/ApplicationDelay.vue');
// 我审批的
const AccraditationDelay = () =>
    import ('../views/sevenDelay/AccraditationDelay.vue');
// 我发起的
const SponsoredDelay = () =>
    import ('../views/sevenDelay/SponsoredDelay.vue');
// 下属员工
const SubordinatesDelay = () =>
    import ('../views/sevenDelay/SubordinatesDelay.vue');
// 下属员工详情
const SubordinatesInfoDelay = () =>
    import ('../views/sevenDelay/SubordinatesInfoDelay.vue');
// 审批详情
const ApproveDetailDelay = () =>
    import ('../views/sevenDelay/ApproveDetailDelay.vue');

// 隐私保护
const Privacy = () =>
    import ('../views/privacy/Privacy.vue');

// 费用报销
const Reimbursement = () =>
    import ('../views/financial/reimbursement/Reimbursement.vue')

// 财务start
//我要申请
const FinApplication = () =>
    import ('../views/financial/reimbursement/fin-application.vue')
    //费用项目
const FinCostItem = () =>
    import ('../views/financial/reimbursement/fin-costItem.vue')
    //冲抵借款
const FinBorrowMoney = () =>
    import ('../views/financial/reimbursement/fin-borrowMoney.vue')
    //我发起的
const FinSponsored = () =>
    import ('../views/financial/reimbursement/fin-sponsored.vue')
    //我审批的
const FinAccraditation = () =>
    import ('../views/financial/reimbursement/fin-accraditation.vue')
    // 审批详情
const FinApproveDetail = () =>
    import ('../views/financial/reimbursement/fin-approveDetail.vue');
// 审批
const FinApproval = () =>
    import ('../views/financial/reimbursement/fin-approval.vue');
// 审批
const FinApproveEdit = () =>
    import ('../views/financial/reimbursement/fin-approveEdit.vue');



Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/login'
    },
    {
        path: '/business',
        name: 'business',
        component: Business,
        meta: {
            title: '招商考核',
            requireToken: true,
            // keepAlive: true // 通过此字段判断是否需要缓存当前组件 
        }
    },
    {
        path: '/application',
        name: 'application',
        component: Application,
        meta: {
            title: '我要申请',
            requireToken: true
        }
    },
    {
        path: '/accraditation',
        name: 'accraditation',
        component: Accraditation,
        meta: {
            title: '我审批的',
            requireToken: true
        }
    },
    {
        path: '/sponsored',
        name: 'sponsored',
        component: Sponsored,
        meta: {
            title: '我发起的',
            requireToken: true,
        }
    },
    {
        path: '/subordinates',
        name: 'subordinates',
        component: Subordinates,
        meta: {
            title: '下属员工',
            requireToken: true,
            keepAlive: true
        }
    },
    {
        path: '/subordinatesInfo',
        name: 'subordinatesInfo',
        component: SubordinatesInfo,
        meta: {
            title: '下属员工招商考核',
            requireToken: true
        }
    },
    {
        path: '/approveDetail',
        name: 'approveDetail',
        component: ApproveDetail,
        meta: {
            title: '',
            requireToken: true
        }
    },
    {
        path: '/sevenDelay',
        name: 'sevenDelay',
        component: SevenDelay,
        meta: {
            title: '7天延期',
            requireToken: true,
        }
    },
    {
        path: '/applicationDelay',
        name: 'applicationDelay',
        component: ApplicationDelay,
        meta: {
            title: '我要申请',
            requireToken: true
        }
    },
    {
        path: '/accraditationDelay',
        name: 'accraditationDelay',
        component: AccraditationDelay,
        meta: {
            title: '我审批的',
            requireToken: true
        }
    },
    {
        path: '/sponsoredDelay',
        name: 'sponsoredDelay',
        component: SponsoredDelay,
        meta: {
            title: '我发起的',
            requireToken: true,
        }
    },
    {
        path: '/subordinatesDelay',
        name: 'subordinatesDelay',
        component: SubordinatesDelay,
        meta: {
            title: '下属员工',
            requireToken: true,
            keepAlive: true,
            isFresh: false, //是否刷新页面
            scrollTop: 0, //缓存时，当前页面的高度
        }
    },
    {
        path: '/subordinatesInfoDelay',
        name: 'subordinatesInfoDelay',
        component: SubordinatesInfoDelay,
        meta: {
            title: '下属员工',
            requireToken: true
        }
    },
    {
        path: '/approveDetailDelay',
        name: 'approveDetailDelay',
        component: ApproveDetailDelay,
        meta: {
            title: '',
            requireToken: true
        }
    },

    {
        path: '/login',
        name: 'login',
        component: Login,
        meta: {
            title: '登录',
        }
    },
    {
        path: '/deskTop',
        name: 'deskTop',
        component: DeskTop,
        meta: {
            title: '工作台',
            showBottomTabBar: true,
        }
    },
    {
        path: '/notice',
        name: 'notice',
        component: Notice,
        meta: {
            title: '消息分类',
            requireToken: true
        }
    },
    {
        path: '/noticeList',
        name: 'noticeList',
        component: NoticeList,
        meta: {
            title: '消息列表',
            requireToken: true
        }
    },
    {
        path: '/mine',
        name: 'mine',
        component: Mine,
        meta: {
            title: '我的',
            showBottomTabBar: true,
        }
    },
    {
        path: '/changePassword',
        name: 'changePassword',
        component: ChangePassword,
        meta: {
            title: '修改密码',
            requireToken: true
        }
    },

    {
        path: '/performanceTabs',
        name: 'performanceTabs',
        component: PerformanceTabs,
        meta: {
            title: '绩效考核',
            requireToken: true,
            keepAlive: true
        }
    },
    {
        path: '/myPerformance',
        name: 'myPerformance',
        component: MyPerformance,
        meta: {
            title: '绩效结果',
            requireToken: true
        }
    },
    {
        path: '/appraisalIndexDescription',
        name: 'appraisalIndexDescription',
        component: AppraisalIndexDescription,
        meta: {
            title: '考核指标说明',
            requireToken: true
        }
    },
    {
        path: '/privacy',
        name: 'privacy',
        component: Privacy,
        meta: {
            title: '隐私权政策',
            requireToken: true
        }
    },
    {
        path: '/reimbursement',
        name: 'reimbursement',
        component: Reimbursement,
        meta: {
            title: '费用报销',
            requireToken: true,
        }
    },
    {
        path: '/finApplication',
        name: 'finApplication',
        component: FinApplication,
        meta: {
            title: '我要申请',
            requireToken: true,
        }
    },
    {
        path: '/finCostItem',
        name: 'finCostItem',
        component: FinCostItem,
        meta: {
            title: '费用项目',
            requireToken: true,
        }
    },
    {
        path: '/finBorrowMoney',
        name: 'finBorrowMoney',
        component: FinBorrowMoney,
        meta: {
            title: '冲抵借款',
            requireToken: true,
        }
    },
    {
        path: '/finSponsored',
        name: 'finSponsored',
        component: FinSponsored,
        meta: {
            title: '我发起的',
            requireToken: true,
        }
    },
    {
        path: '/finAccraditation',
        name: 'finAccraditation',
        component: FinAccraditation,
        meta: {
            title: '我审批的',
            requireToken: true,
        }
    },
    {
        path: '/finApproval',
        name: 'finApproval',
        component: FinApproval,
        meta: {
            title: '我审批的',
            requireToken: true
        }
    },
    {
        path: '/finApproveDetail',
        name: 'finApproveDetail',
        component: FinApproveDetail,
        meta: {
            title: '详情页',
            requireToken: true,
        }
    },
    {
        path: '/finApproveEdit',
        name: 'finApproveEdit',
        component: FinApproveEdit,
        meta: {
            title: '编辑页',
            requireToken: true
        }
    },
]
const router = new VueRouter({
        mode: 'history',
        base: process.env.BASE_URL,
        routes,
        // scrollBehavior(to, from, savedPosition) {
        //     if (savedPosition) {
        //         return savedPosition
        //     } else {
        //         if (from.meta.keepAlive) {
        //             from.meta.savedPosition = Number(localStorage.getItem('scrollTop'));
        //         }
        //         return { x: 0, y: to.meta.savedPosition || 0 }
        //     }
        // }
    })
    // 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
    if (to.name == "approveDetail" || to.name == "noticeList") {
        to.meta.title = to.query.title;
    }
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    if (to.query.token) {
        store.commit('setToken', to.query.token);
        // store.commit('setToken', to.query.token);
        next()
    }
    if (to.matched.some((route) => route.meta.requireToken)) {
        if (store.state.token) {
            next()
        } else {
            console.log('哪有token');
        }
    } else {
        next()
    }
})
export default router